<?php

/**
 * 配置参数
 * 运行加载文件
 */

if (!defined('IN_SEXMALL'))
{
	die('Hacking attempt');
}

error_reporting(E_ALL);

if (__FILE__ == '')
{
	die('Fatal error code: 0');
}

/* 初始化设置 */
@ini_set('memory_limit',          '64M');
@ini_set('session.cache_expire',  180);
@ini_set('session.use_trans_sid', 0);
@ini_set('session.use_cookies',   1);
@ini_set('session.cookie_lifetime',   7200);
@ini_set('session.gc_maxlifetime',   900);
@ini_set('session.auto_start',    0);
@ini_set('display_errors',        1);

/* 取得当前所在的根目录 */
define('ROOT_PATH', str_replace('load.php', '', str_replace('\\', '/', __FILE__)));

// 设置目录分隔符
if (DIRECTORY_SEPARATOR == '\\')
{
	@ini_set('include_path', '.;' . ROOT_PATH);
}
else
{
	@ini_set('include_path', '.:' . ROOT_PATH);
}

// 设置PHP_SELF常量
if(isset($_SERVER['PHP_SELF']))
{
	$_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
}
$php_self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
if ('/' == substr($php_self, -1))
{
	$php_self .= 'index.php';
}
define('PHP_SELF', $php_self);


/* 配置文件目录 */
define('CONF_DIR', ROOT_PATH . 'config/');

// 模块目录
define('MODEL_DIR', ROOT_PATH . 'model/');

// 模板目录
define('THEME_DIR', ROOT_PATH . 'themes/');

// 临时目录
define('TEMP_DIR', ROOT_PATH . 'temp/');

define('DATA_DIR', 'data');

// 定义debug模式
if (defined('DEBUG_MODE') == false)
{
	define('DEBUG_MODE', 0);
}
if ((DEBUG_MODE & 1) == 1)
{
	error_reporting(E_ALL);
}
else
{
	error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
}
if ((DEBUG_MODE & 4) == 4)
{
	include(ROOT_PATH . 'includes/lib.debug.php');
}


/* 加载配置文件 */
require(CONF_DIR . 'base.config.php');

/* 设置时区 */
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
	date_default_timezone_set($timezone);
}


/***** 加载主文件 *****/
require (ROOT_PATH . 'main.php');




/* 模块参数 */
$model = empty($_REQUEST['m']) ? 'index' : trim($_REQUEST['m']);


// 验证码不创建smarty对象
if ($model == 'captcha')
{
	define('INIT_NO_SMARTY', true);
}

/* 创建 Smarty 对象。*/
if (!defined('INIT_NO_SMARTY'))
{
	header("Cache-Control:no-cache");
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	header('Content-type: text/html; charset='.CHARSET);

	require(ROOT_PATH . 'includes/cls_template.php');
	$smarty = new cls_template;

	$smarty->cache_lifetime = 3600;
	$smarty->template_dir   = THEME_DIR . UI . '/';
	$smarty->cache_dir      = TEMP_DIR . UI . '/caches';
	$smarty->compile_dir    = TEMP_DIR . UI . '/compiled';

	if ((DEBUG_MODE & 2) == 2)
	{
		$smarty->direct_output = true;
		$smarty->force_compile = true;
	}
	else
	{
		$smarty->direct_output = false;
		$smarty->force_compile = false;
	}

	if ((DEBUG_MODE & 2) != 2)
	{
		$smarty->caching = true;
	}

	$smarty->assign('charset', 			CHARSET);

	$smarty->assign('cookie_expire', 	COOKIE_EXPIRE);

	// 文件资源版本(css/js)
	$smarty->assign('wap_version', 	WAP_VERSION);

	// 返回链接
	$referer = htmlspecialchars($_SERVER['HTTP_REFERER']);
	$referer = empty($referer) ? 'index.html' : $referer;
	$smarty->assign('referer', 	$referer);

	// UI
	$smarty->assign('ui', 	UI);

	// 页面调试
	if ($_GET['debug'] ==1){
		setcookie("debug", 1, 0, COOKIE_PATH, COOKIE_DOMAIN);
	}
}

require include_model_file($model);


/* 判断是否支持 Gzip 模式 */
if (!defined('INIT_NO_SMARTY') && gzip_enabled())
{
	ob_start('ob_gzhandler');
}
else
{
	ob_start();
}

?>